package com.bbm.communitysystem.controller.chat;


import cn.hutool.core.bean.BeanUtil;
import com.bbm.communitysystem.core.domain.R;
import com.bbm.communitysystem.domain.ChatHistory;
import com.bbm.communitysystem.domain.vo.ChatHistoryVo;
import com.bbm.communitysystem.service.IChatHistoryService;
import com.bbm.communitysystem.tools.DemoDate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bbm
 * @since 2025-03-01
 */
@Tag(name = "AI聊天记录历史列表")
@RestController
@RequestMapping("/chat-history")
@RequiredArgsConstructor
public class ChatHistoryController {

    private final IChatHistoryService chatHistoryService;


    @Operation(summary = "获取AI聊天记录历史列表")
    @GetMapping("/{pageId}")
    public R getChatHistoryList(@PathVariable("pageId") Long pageId) {

        List<ChatHistory> list = chatHistoryService.lambdaQuery()
                .eq(ChatHistory::getChatPageId, pageId)
                .eq(ChatHistory::getStatus, 1)
                .list();

        List<ChatHistoryVo> chatHistoryVoList = new ArrayList<>();



        list.forEach(item -> {
            ChatHistoryVo chatHistoryVo = new ChatHistoryVo();

            chatHistoryVo.setId(item.getId());
            chatHistoryVo.setChatPageId(item.getChatPageId());
            chatHistoryVo.setType(item.getType());
            chatHistoryVo.setThink(false);
            chatHistoryVo.setThinkContent(item.getThinkContent());
            chatHistoryVo.setContent(item.getContent());
            chatHistoryVo.setShowTime(DemoDate.getPostDate(item.getCreateTime()));

            chatHistoryVoList.add(chatHistoryVo);
        });

        return R.ok("获取成功", chatHistoryVoList);
    }



}

